package com.liu.communitysystemend.module.complaints.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.complaints.domain.ComplaintsDto;
import com.liu.communitysystemend.module.complaints.service.ComplaintsService;
import com.liu.communitysystemend.module.complaints.domain.Complaints;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-03-02 11:34
 */
@RestController
@RequestMapping("/api/complaints")
public class ComplaintsController {
    @Autowired
    private ComplaintsService complaintsService;

    @ApiOperation("根据id获取投诉信息")
    @GetMapping("/get/{id}")
    public Result<Complaints> getComplaints(@PathVariable("id")String id){
        return Result.success(complaintsService.getComplaintsById(id));
    }

    @ApiOperation("更新投诉信息")
    @PostMapping("modify")
    public Result<Complaints> save(@RequestBody Complaints complaints) {
        return Result.success(complaintsService.update(complaints));
    }

    @ApiOperation("添加投诉信息")
    @PostMapping("add")
    public Result<Complaints> add(@RequestBody Complaints complaints){
        return Result.success(complaintsService.add(complaints));
    }

    @ApiOperation("查询投诉列表(分页)")
    @PostMapping("page")
    public Result<Page<Complaints>> getPage(@RequestBody Complaints complaints) {
        return Result.success(complaintsService.getPage(complaints));
    }
    @ApiOperation("查询投诉列表(分页)")
    @PostMapping("allPage")
    public Result<Page<ComplaintsDto>> getAllPage(@RequestBody Complaints complaints) {
        return Result.success(complaintsService.getAllPage(complaints));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除投诉")
    public Result deleteById(@PathVariable("id") String id) {
        return complaintsService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }

    @GetMapping("/test")
    @ApiOperation("投诉测试")
    public Result test(){
        return Result.success(complaintsService.test());
    }
}

